package com.wd.mylibrary_near.view.fragment







import android.app.Dialog
import android.view.View
import android.view.Window
import android.view.WindowManager
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import androidx.lifecycle.Observer

import androidx.recyclerview.widget.LinearLayoutManager
import coil.load
import coil.transform.RoundedCornersTransformation


import com.ayvytr.adapter.smart
import com.wd.mylibrary_base.base.BaseFragment
import com.wd.mylibrary_base.bean.NearBean
import com.wd.mylibrary_near.R
import com.wd.mylibrary_near.databinding.FragmentNearBinding
import com.wd.mylibrary_near.viewmodel.NearViewModel


class NearFragment : BaseFragment<NearViewModel,FragmentNearBinding>(R.layout.fragment_near) {
//    val animationView: LottieAnimationView = dataBinding.animationView

    var listt=smart(mutableListOf<NearBean.Result>(),R.layout.near,{ item, position ->
        findViewById<ImageView>(R.id.img).load(item.headPic){
            transformations(RoundedCornersTransformation(360f))
        }
        findViewById<TextView>(R.id.name).text=item.nickName
        findViewById<TextView>(R.id.sex).text=item.sex.toString()
    }) {  }
    override fun initView() {

        viewModel.getNearby(0,100,1,10)
        dataBinding.recNear.adapter=listt
        dataBinding.recNear.layoutManager= LinearLayoutManager(context)


//        animationView.playAnimation() // 播放动画
//        animationView.pauseAnimation() // 暂停动画
//        animationView.repeatCount = -1 // 设置动画无限循环
//        animationView.addAnimatorListener(object : Animator.AnimatorListener {
//
//            override fun onAnimationStart(p0: Animator) {
//
//            }
//
//            override fun onAnimationEnd(p0: Animator) {
//
//            }
//
//            override fun onAnimationCancel(p0: Animator) {
//
//            }
//
//            override fun onAnimationRepeat(p0: Animator) {
//
//            }
//        })

        dataBinding.noischeckAll.setOnClickListener {
           dataBinding.ischeckAll.visibility=View.VISIBLE
           dataBinding.noischeckNv.visibility=View.VISIBLE
           dataBinding.noischeckNan.visibility=View.VISIBLE
            dataBinding.noischeckAll.visibility=View.GONE
            dataBinding.ischeckNv.visibility=View.GONE
            dataBinding.ischeckNan.visibility=View.GONE


        }
        dataBinding.noischeckNv.setOnClickListener {
            dataBinding.noischeckAll.visibility=View.VISIBLE
            dataBinding.ischeckNv.visibility=View.VISIBLE
            dataBinding.noischeckNan.visibility=View.VISIBLE
            dataBinding.ischeckAll.visibility=View.GONE
            dataBinding.noischeckNv.visibility=View.GONE
            dataBinding.ischeckNan.visibility=View.GONE
        }
        dataBinding.noischeckNan.setOnClickListener {
            dataBinding.noischeckAll.visibility=View.VISIBLE
            dataBinding.noischeckNv.visibility=View.VISIBLE
            dataBinding.ischeckNan.visibility=View.VISIBLE
            dataBinding.ischeckAll.visibility=View.GONE
            dataBinding.ischeckNv.visibility=View.GONE
            dataBinding.noischeckNan.visibility=View.GONE
        }




        dataBinding.rightL.setOnClickListener {
            val customDialog = context?.let { Dialog(it) }
            customDialog?.requestWindowFeature(Window.FEATURE_NO_TITLE)
            customDialog?.setContentView(R.layout.dialog)

            // 设置弹窗显示的宽度为屏幕宽度
            customDialog?.window?.setLayout(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT
            )

            //设置监听器关闭弹窗
            customDialog?.findViewById<Button>(R.id.start)?.setOnClickListener {
                dataBinding.weizhi.visibility=View.GONE
                dataBinding.svga.visibility=View.VISIBLE
                dataBinding.recNear.visibility=View.VISIBLE
                customDialog.dismiss()
            }
            customDialog?.findViewById<Button>(R.id.stop)?.setOnClickListener {


                customDialog.dismiss()
            }

            // 显示弹窗
            customDialog?.show()
        }
        dataBinding.shua.setOnClickListener {
            dataBinding.svga.visibility=View.GONE
        }


    }



    override fun dataObserve() {
        viewModel.nearby.observe(this, Observer {
            if(it.result!=null){
                listt.update(it.result,true)
            }

        })


    }

}


